
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<link rel="stylesheet" href="../../../static/font-awesome-4.7.0/css/font-awesome.min.css">
	<link rel="stylesheet" href="../../../static/vui/css/vui.css">

	<script type="text/javascript" src="../../../static/js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../../../static/js/jquery.cookie.min.js"></script>
	<script type="text/javascript" src="../../../static/layer/layer.js"></script>
	<script type="text/javascript" src="../../../static/vui/js/vui.js"></script>
	<script type="text/javascript" src="../../../static/vui/js/datagrid.js"></script>
	<script type="text/javascript" src="../../../static/js/common.js"></script>
</head>
<body>

<div id="formArea">
	<table class="table-top">
		<tr>
			<td><label>单据类型名称</label></td>
			<td><input type="text" class="input" name="name" autocomplete="off"/></td>
			<td>
				<button class="button" id="query"><span>查询</span></button>
			</td>
		</tr>

	</table>
</div>

<div id="table"></div>

<script>
    var editArea = 	['450px', '400px'];

    $(function(){

        $('#query').click(function(){
            $("#table").datagrid("reload",app.serializeForm());
        });

        var hideOpt4 = app.getHideOpt(4);
        var hideOpt2 = app.getHideOpt(2);

        $('#table').datagrid({
            url:app.BASE_API_URL+'print/page',simplePagination:true,width:700,
            queryParams:{companyId:app.getCompanyId()},
            columns:[
                {field:'bussTypeName',title:'单据类型',width:150},
                {field:'printDefault',title:'模板类型',width:100,formatter:function (row) {
                        return row.customerId == '001002006008' ? '系统':'用户';
                    }},
                {field:'printDefault',title:'默认打印模板',width:100,formatter:function (row) {
						return row.printDefault == 1 ? '是':'否';
                    }},
                {title:'操作',width:200,formatter:function(row){
                        var add = app.getOpt(row.id,'新增','dh');
                        var edit = app.getOpt(row.id,'编辑','edit');
                        var setDefault = app.getOpt(row.id,'设为默认','green');
                        var del = app.getOpt(row.id,'删除','del');

                        if( row.customerId == '001002006008' ){
                            if(row.printDefault == 1){
                                return add+edit+hideOpt2+hideOpt4;
                            }else{
                                return add+edit+hideOpt2+setDefault;
                            }
                        }else{
                            if(row.printDefault == 1){
                                return add+edit+hideOpt2+hideOpt4;
                            }else{
                                return add+edit+del+setDefault;
                            }
                        }



                        //app.getHideOpt(4);
                    }}
            ],
            loadSuccess:loadDataSuccess
        });
    });

    function loadDataSuccess(){
        $('.vui-opt-del').click(function(){
            var row = $(this).parent().parent().parent().data();

            if(row.printDefault == 1){
                app.message(layer,'默认模板不能删除');
                return;
            }

            if(row.customerId == '001002006008'){
                app.message(layer,'系统初始化模板不能删除');
                return;
            }

            layer.confirm('确定要删除选中的记录吗？', {icon: 3, title:'提示'}, function(index){
                app.request({
                    url:'print/delete',
                    data:{id:row.id,defaultStone:row.defaultStone},
                    success:function (resp) {
                        app.actionSuccess_index(resp,index);
                    }
                });

            });
        });

        $('.vui-opt-edit').click(function(){
            var row = $(this).parent().parent().parent().data();
            var o = {loginUserId:top.loginUserId,customerId:top.customerId,loginCompanyId:top.loginCompanyId,loginCompanyLogicalCode:top.loginCompanyLogicalCode};
            var url = app.getBaseUrl()+"/html/system/print/print_add.html?bussType="+row.bussType+"&id="+row.id;
            for( var n in o ){
                url += "&"+n+"="+o[n];
            }
            window.open(url, "_blank");
        });

        $('.vui-opt-dh').click(function(){
            var row = $(this).parent().parent().parent().data();
            var o = {loginUserId:top.loginUserId,customerId:top.customerId,loginCompanyId:top.loginCompanyId,loginCompanyLogicalCode:top.loginCompanyLogicalCode};
            var url = app.getBaseUrl()+"/html/system/print/print_add.html?bussType="+row.bussType;
            for( var n in o ){
                url += "&"+n+"="+o[n];
            }
            window.open(url, "_blank");
        });

        $('.vui-opt-green').click(function(){
            var row = $(this).parent().parent().parent().data();
            layer.confirm('确定把选中的模板设置为默认模板吗？', {icon: 3, title:'提示'}, function(index){
                app.request({
                    url:'print/setDefault',
                    data:{id:row.id,bussType:row.bussType},
                    success:function(resp){
                        app.actionSuccess_index(resp,index);
                    }
                });

            });
        });
    }
</script>

</body>
</html>